/*
 *  作业3
 */
package com.stage_1.module_3;

import java.util.*;

public class StudentTest {
    public static void main(String[] args){
        /*
         *  2.定义Map集合，用Student对象作为key，用字符串(此表示表示学生的住址)作为value
         */
        Map<Student,String> m = new HashMap<>();
        m.put(new Student("张三", 16), "北京");
        m.put(new Student("李四", 19), "上海");
        m.put(new Student("王五", 18), "广州");

        /*
         *  3.利用四种方式遍历Map集合中的内容，格式：key::value
         */
        for (Student s : m.keySet()){
            System.out.println(s.toString()+"::"+m.get(s));
        }
        System.out.println("-------------------------------------------------");

        for (String s : m.values()){
            System.out.println("key ::"+s);
        }
        System.out.println("-------------------------------------------------");

        for (Map.Entry<Student, String> s : m.entrySet()){
            System.out.println(s.getKey()+"::"+s.getValue());
        }
        System.out.println("-------------------------------------------------");

        Iterator<Map.Entry<Student, String>> it = m.entrySet().iterator();
        while(it.hasNext()){
            Map.Entry<Student, String> en = it.next();
            System.out.println(en.getKey() + "::"+ en.getValue());
        }

    }
}
